xlv.obj.input={
	extend:function(){
	},
	implement:function(){
		this.implement('xlv.imp.mvc');
		this.implement('xlv.imp.editor');		
	},
	create:function(tag){
		var div=document.createElement((tag||'div'));
		div.setAttribute('xlvobject','xlv.obj.input');
		return div;			
	},
	pub:{
		validate:{
			required: {type: 'required', regExp: /[^.*]/, msg: 'This field is required.'},
			alpha: {type: 'alpha', regExp: /^[a-z ._-]+$/i, msg: 'This field accepts alphabetic characters only.'},
			alphanum: {type: 'alphanum', regExp: /^[a-z0-9 ._-]+$/i, msg: 'This field accepts alphanumeric characters only.'},
			number: {type: 'number', regExp: /^[0-9]+$/i, msg: 'This field accepts alphanumeric characters only.'},
			integer: {type: 'integer', regExp: /^[-+]?\d+$/, msg: 'Please enter a valid integer.'},
			real: {type: 'real', regExp: /^[-+]?\d*\.?\d+$/, msg: 'Please enter a valid number.'},
			date: {type: 'date', regExp: /^((((0[13578])|([13578])|(1[02]))[\/](([1-9])|([0-2][0-9])|(3[01])))|(((0[469])|([469])|(11))[\/](([1-9])|([0-2][0-9])|(30)))|((2|02)[\/](([1-9])|([0-2][0-9]))))[\/]\d{4}$|^\d{4}$/, msg: 'Please enter a valid date (mm/dd/yyyy).'},
			email: {type: 'email', regExp: /^[a-z0-9._%-]+@[a-z0-9.-]+\.[a-z]{2,4}$/i, msg: 'Please enter a valid email.'},
			phone: {type: 'phone', regExp: /^[\d\s ().-]+$/, msg: 'Please enter a valid phone.'},
			ip:{type: 'ip',regExp: /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/,msg:'enter a valid IP' },
			url: {type: 'url', regExp: /^(http|https|ftp)\:\/\/[a-z0-9\-\.]+\.[a-z]{2,3}(:[a-z0-9]*)?\/?([a-z0-9\-\._\?\,\'\/\\\+&amp;%\$#\=~])*$/i, msg: 'Please enter a valid url.'}
			}
	},
	properties:{
		dmName:null,
		dmPath:null,
		password:false,
		validateRegExp:null
	},
	method:{
		construct:function(){
			var v=this.$V;
			v.editor=xlv.util.isTag(this,'input') ? this:xlv.util.findDirectChild(this,{tag:'input'});
			if(!v.editor){
				v.editor=document.createElement('input');
				v.editor.setAttribute('type',(this.$P.password)?'Password':'text');
				v.editor.style.width=this.style.width;
				this.appendChild(v.editor);
				this.styleFor(v.editor);
			}
		},
		initial:function(){
			this.addEventHandler('blur','_blur',this.$V.editor);
			this.addEventHandler('focus','_focus',this.$V.editor);
		},
		styleFor:function(editor){
		},
		dispose:function(){
		},
		_blur:function(event){
			if(this.editor_editing())this._editor_endEdit(true);
		},
		_focus:function(event){
			if(!this.editor_editing())this._editor_startEdit();
		},
		/**mvc imp*/
		mvc_valueFromModel:function(dm){
			return this.mvc_isModel(dm) ? dm.getValue(this.$P.dmPath) : null;
		},
		mvc_valueToModel:function(value,dm){
			if(this.mvc_isModel(dm)) dm.setValue(value,this.$P.dmPath);
		},
		mvc_beforeModelChanged:function(model,notify,memo){
			if(this.mvc_isModel(model)&& notify=='cursorMove'&& this.editor_editing())
				this._editor_endEdit(true);
		},
		mvc_valueFromView:function(){
			return this.editor_valueFromEditor();
		},
		mvc_valueToView:function(value){
			this.editor_valueToEditor(value);
		},
		/**editor imp*/
		editor_startEdit:function(){
			Element.removeClassName(this.$V.editor,'validate_error');
		},
		editor_valueToEditor:function(value){
			this.$V.editor.value=value;
		},
		editor_valueFromEditor:function(){
			return this.$V.editor.value;
		},
		editor_endEdit:function(commit){
			var dm=this.mvc_getModel();
			if(dm && commit)this.mvc_valueToModel(this.editor_valueFromEditor(),dm);
			if(dm && !commit)this.editor_valueToEditor(this.mvc_valueFromModel(dm));
		},
		editor_validate:function(){
			var valid=(this.$P.validateRegExp)?this.$P.validateRegExp.match(this.editor_valueFromEditor()):true;
			if(valid) Element.removeClassName(this.$V.editor,'validate_error');
			else Element.addClassName(this.$V.editor,'validate_error');
			return valid;
		}
	}
};
